<template>
	<view class="searchBox">
		<view class="header" :style="'padding-top:'+barHeight+'px'">
			<view class="cancel" @click="back">取消</view>
			<u-search height="40" @search="search" @custom="search" showAction="true" bgColor="#FFFFFF"
				borderColor="#D7D7D7" v-model="name" :showAction="true" actionText="搜索"></u-search>
		</view>
		<view class="hot">
			<view class="hot_tit">
				热门搜索
			</view>
			<view class="hot_key">
				<view class="key_name" @click="clickkey(item)" v-for="item in keyname">
					{{item.name}}
				</view>
			</view>
		</view>
		<!-- <scroll-view scroll-y="true" class="lists" @scrolltolower="lower()">

		</scroll-view> -->
	</view>
</template>

<script>
	let QQMapWX = require('../../common/qqmap-wx-jssdk.min.js');
	export default {
		data() {
			return {
				page: 1,
				finish: false,
				list: [],
				name: '',
				barHeight: '',
				city: '',
				keyname: []
			};
		},
		onLoad(options) {
			this.barHeight = uni.getSystemInfoSync().statusBarHeight;
			this.getkey()
			this.equiptype = uni.getSystemInfoSync().platform == 'ios' ? 2 : 1
			this.type = Number(options.type)
			let that = this
			uni.getLocation({
				type: 'wgs84',
				success: function(res) {
					console.log(res)
					that.longitude = res.longitude
					that.latitude = res.latitude
					var qqmapsdk = new QQMapWX({
						key: 'LNWBZ-4DTKU-JQCVV-23LKL-4GM2V-2RBQI' // 必填
					});
					qqmapsdk.reverseGeocoder({
						location: '',
						success: function(res) {
							that.city = res.result.address_component.city
						}
					})
				}
			});
		},
		methods: {
			clickkey(item) {
				uni.$u.route({
					url: 'pages/common/oldSearchb',
					params: {
						name: item.name,
						id: item.id
					}
				})
			},
			detail(id) {
				if (this.type === 0) {
					uni.$u.route({
						url: 'pagesA/index/detail',
						params: {
							id: id
						}
					})
				} else if (this.type === 1) {
					uni.$u.route({
						url: 'pages/task/detail',
						params: {
							id: id
						}
					})
				} else if (this.type === 2) {
					uni.$u.route({
						url: 'pages/serve/detail',
						params: {
							id: id
						}
					})
				}
			},
			getkey() {
				uni.$u.http.post('/quick').then(res => {
					if (res.code == 1) {
						// console.log(res)
						this.keyname = res.data
					}
				}).catch((res) => {})
			},
			search() {
				console.log(888)
				// if (this.finish) {
				// 	return
				// }

				if (this.name == '') {
					this.toast('请输入搜索内容')
					return
				}

				uni.$u.route({
					url: 'pages/common/oldSearchb',
					params: {
						name: this.name
					}
				})

				// uni.$u.http.post('/search', {
				// 	page: this.page,
				// 	name: this.name
				// }).then(res => {
				// 	if (res.code == 1) {
				// 		console.log(res)
				// 		this.list = this.list.concat(res.data)

				// 		if (res.data.length === 0) {
				// 			this.finish = true
				// 		}
				// 	}
				// }).catch((res) => {})

			},
			lower() {
				this.page++
				this.getList()
			},
			reload() {
				this.finish = false
				this.page = 1
				this.list = []
				this.getList()
			},
			getList() {
				if (this.finish) {
					return
				}
				let data = {
					city: this.city,
					lng: this.longitude,
					lat: this.latitude,
					page: this.page,
					name: this.name,
					type: this.type,
					equiptype: this.equiptype
				}
				uni.showModal({
					title: '提示',
					content: JSON.stringify(data),
					success: function(res) {
						if (res.confirm) {
							console.log('用户点击确定');
						} else if (res.cancel) {
							console.log('用户点击取消');
						}
					}
				});
				uni.$u.http.post('/search', {
					city: this.city,
					lng: this.longitude,
					lat: this.latitude,
					page: this.page,
					name: this.name,
					type: this.type,
					equiptype: this.equiptype
				}).then(res => {
					if (res.code == 1) {
						this.list = this.list.concat(res.data)
						if (res.data.length === 0) {
							this.finish = true
						}
					}
				}).catch((res) => {

				})
			},
		}
	}
</script>
<style lang="scss" scoped>
	.searchBox {
		.header {
			display: flex;
			align-items: center;
			height: 88rpx;
			padding: 0 20rpx;
			// background: linear-gradient(to left, #FFC141, #FFDF41);
			/* #ifdef MP-WEIXIN */
			padding-right: 220rpx;
			.cancel{
				font-size: 28rpx;
				color: #666;
				margin-right: 10rpx;
			}

			/* #endif */
			.inputBox {
				flex: 1;
				padding: 0 20rpx;
				background: #fff;
				border-radius: 40rpx;
				height: 70rpx;
				display: flex;
				align-items: center;
				border: 2rpx solid #D7D7D7;

				.search {
					width: 40rpx;
					height: 40rpx;
				}

				.keyword {
					width: 100%;
					height: 60rpx;
					line-height: 60rpx;
				}
			}

			.btn {
				margin-left: 20rpx;
				font-weight: 400;
				font-size: 32rpx;
				color: #676767;
				line-height: 42rpx;
			}
		}

		.hot {
			margin: 40rpx 30rpx;

			.hot_tit {
				margin: 20rpx 0;
				font-size: 28rpx;
				line-height: 40rpx;
			}

			.hot_key {
				display: flex;
				flex-direction: row;
				flex-wrap: wrap;


				.key_name {
					margin: 10rpx 0;
					margin-right: 35rpx;
					padding: 20rpx;
					background: #FAFAFA;
					border-radius: 30rpx;
					display: flex;
					align-items: center;
					justify-content: center;
					font-size: 26rpx;
				}
			}
		}


		.lists {
			.list {
				display: flex;
				margin: 10rpx 20rpx;
				padding: 20rpx;
				background-color: #fff;
				border-radius: 10rpx;

				.cover {
					width: 180rpx;
					height: 180rpx;
					margin-right: 20rpx;
					flex-direction: 0;
					border-radius: 10rpx;
					flex-shrink: 0;
				}

				.address {
					font-size: 25rpx;
					color: #575859;
					height: 90rpx;
				}

				.info {
					flex: 1;

					.title {
						display: flex;
						align-items: center;

						.l {
							flex: 1;
							overflow: hidden;
							white-space: nowrap;
							text-overflow: ellipsis;
							font-weight: bold;
						}

						.r {
							color: #428DFC;
							font-size: 24rpx;
							flex-shrink: 0;
							display: flex;
							align-items: center;
						}
					}

					.num {
						display: flex;
						align-items: center;
						justify-content: space-between;

						.l {
							background-color: #FFFAE5;
							height: 36rpx;
							border-radius: 18rpx;
							color: #FF8007;
							font-size: 20rpx;
							padding: 0 20rpx;
							display: flex;
							align-items: center;
						}

						.r {
							color: #FF5B1A;
							font-size: 40rpx;

							.icon {
								font-size: 28rpx;
							}
						}
					}
				}
			}

			.list2 {
				display: flex;
				margin: 10rpx 20rpx;
				padding: 20rpx;
				background-color: #fff;
				border-radius: 10rpx;
				position: relative;

				.cover {
					width: 170rpx;
					height: 170rpx;
					margin-right: 20rpx;
					flex-direction: 0;
					border-radius: 10rpx;
					flex-shrink: 0;
				}

				.address {
					font-size: 25rpx;
					color: #575859;
					margin: 10rpx 0 20rpx;
				}

				.vip {
					position: absolute;
					left: 0;
					top: 40rpx;
					width: 74rpx;
					height: 44rpx;

					.icon {
						width: 74rpx;
						height: 44rpx;
					}

					.word {
						width: 74rpx;
						height: 44rpx;
						display: flex;
						align-items: center;
						justify-content: center;
						color: #191615;
						font-size: 20rpx;
						position: absolute;
						left: 0;
						top: -10rpx;
						font-weight: bold;
					}
				}

				.info {
					flex: 1;

					.title {
						display: flex;
						align-items: center;

						.l {
							flex: 1;
							overflow: hidden;
							white-space: nowrap;
							text-overflow: ellipsis;
							font-weight: bold;
						}

						.r {
							color: #428DFC;
							font-size: 24rpx;
							flex-shrink: 0;
							display: flex;
							align-items: center;
						}
					}

					.num {
						display: flex;
						align-items: center;
						justify-content: space-between;

						.l {
							display: flex;
							align-items: center;

							.type {
								color: #999999;
								font-size: 24rpx;
							}

							.word {
								background-color: #FFFAE5;
								height: 36rpx;
								border-radius: 18rpx;
								color: #FF8007;
								font-size: 20rpx;
								padding: 0 20rpx;
								display: flex;
								align-items: center;
							}
						}

						.r {
							color: #FF5B1A;
							font-size: 40rpx;

							.icon {
								font-size: 28rpx;
							}
						}
					}
				}
			}

			.list1 {
				display: flex;
				margin: 10rpx 20rpx;
				padding: 20rpx;
				background-color: #fff;
				border-radius: 10rpx;
				align-items: center;
				position: relative;

				.vip {
					position: absolute;
					left: 0;
					top: 40rpx;
					width: 74rpx;
					height: 44rpx;

					.icon {
						width: 74rpx;
						height: 44rpx;
					}

					.word {
						width: 74rpx;
						height: 44rpx;
						display: flex;
						align-items: center;
						justify-content: center;
						color: #191615;
						font-size: 20rpx;
						position: absolute;
						left: 0;
						top: -10rpx;
						font-weight: bold;
					}
				}

				.cover {
					width: 140rpx;
					height: 140rpx;
					margin-right: 20rpx;
					flex-direction: 0;
					border-radius: 10rpx;
					flex-shrink: 0;
				}

				.address {
					font-size: 25rpx;
					color: #575859;
				}

				.moeny {
					font-size: 30rpx;
					color: #FF5B1A;
					margin-left: 40rpx;
				}

				.info {
					flex: 1;

					.title {
						display: flex;
						align-items: center;

						.l {
							flex: 1;
							overflow: hidden;
							white-space: nowrap;
							text-overflow: ellipsis;
							font-weight: bold;
						}

						.r {
							color: #428DFC;
							font-size: 24rpx;
							flex-shrink: 0;
							display: flex;
							align-items: center;
						}
					}

					.types {
						display: flex;
						align-items: center;
						margin: 20rpx 0;

						.btn {
							background: #FFFAE5;
							height: 36rpx;
							border-radius: 18rpx;
							padding: 0 10rpx;
							display: flex;
							align-items: center;
							justify-content: center;
							color: #FF8007;
							font-size: 24rpx;
							margin-right: 10rpx;
						}

						.btn1 {
							background-color: #E9F3FF;
							color: #428DFC;
						}
					}

					.numBox {
						display: flex;
						align-items: center;

						.num {
							display: flex;
							align-items: center;
							font-size: 22rpx;
							margin-left: 10rpx;

							.word {
								color: #428DFC;
							}
						}
					}
				}
			}

		}
	}
</style>
